<!--
 * @Date: 2020-03-17 17:58:16
 * @LastEditors: 黄栋
 * @LastEditTime: 2020-03-18 10:38:45
 * @FilePath: /cloudAdmin/src/views/market/promotion/coupon4.vue
 -->
 
<template>
  <div>
    <el-card>
      <div slot="header" class="clearfix">
        <el-breadcrumb separator-class="el-icon-arrow-right">
          <el-breadcrumb-item :to="{ path: '/promotion' }">店铺营销</el-breadcrumb-item>
          <el-breadcrumb-item>满包邮设置</el-breadcrumb-item> 
        </el-breadcrumb>
      </div>
      <el-form label-width="100px" size="mini">
        <!-- <el-form-item label="活动类型"></el-form-item> -->
        <el-form-item label="是否开启">
          <el-radio-group v-model="editForm.is_free_postage">
            <el-radio :label="1">开启</el-radio>
            <el-radio :label="2">暂不开启</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="条件满">
          <el-input v-model="editForm.free_postage" style="width:200px">
            <template slot="append">元</template>
          </el-input>
        </el-form-item>
        <!-- <el-form-item label="优惠规则"></el-form-item> -->
        <!-- <el-form-item label="适用商品"></el-form-item> -->
      </el-form>
      <div class="dialog-footer" style="text-align:center">
        <el-button size="small" type="primary" @click="dataFormSubmit()">保存</el-button>
      </div>
    </el-card>
  </div>
</template>

<script>
import { edit_set_info, get_co_set } from "@/utils/api/market";

import { mapState, mapActions } from "vuex";

export default {
  computed: {
    ...mapState({
      company: state => state.company
    })
  },
  data() {
    return {
      editForm: {
        search_co_id: "",
        free_postage: "",
        is_free_postage: ""
      }
    };
  },
  created() {
    this.getDataList();
  },
  methods: {
    /**获取满减设置 */
    getDataList() {
      get_co_set({ search_co_id: this.company.id }).then(res => {
        if (res.code == 200) {
          // this.editForm = Object.assign({}, this.editForm, res.data);
          this.editForm.search_co_id = this.company.id;
          this.editForm.is_free_postage = res.data.is_free_postage;
          this.editForm.free_postage = res.data.free_postage;
        }
      });
    },
    /**修改满减设置 */
    dataFormSubmit() {
      edit_set_info(this.editForm).then(res => {
        if (res.code == 200) {
          this.$message({
            message: "操作成功",
            type: "success",
            duration: 1500,
            onClose: () => {
              this.getDataList();
            }
          });
        } else {
          this.$message.error(res.message);
        }
      });
    }
  }
};
</script>

<style lang="less">
.line {
  text-align: center;
  vertical-align: bottom;
}
.el-rowS {
  .el-row {
    .el-col {
      margin-top: 5px;
      margin-bottom: 5px;
    }
  }
}

.itemCard {
  .el-card__header {
    padding: 8px 10px;
  }
}
</style>